package com.zeldu.teacher.homework.controller;

import com.alibaba.fastjson.JSON;
import com.zeldu.common.model.response.QueryResponseResult;
import com.zeldu.common.model.response.ResponseResult;
import com.zeldu.teacher.homework.Dto.*;
import com.zeldu.teacher.homework.entity.Homewrok;
import com.zeldu.teacher.homework.entity.Student_HomeWrok;
import com.zeldu.teacher.homework.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RestController
@CrossOrigin(origins = "*")
public class TeacherController {
    @Autowired
    TeacherService teacherService;

    @RequestMapping("/getAllQestion")
    public  QueryResponseResult<HomeWrokDetailDto_T> findAllQuestion(){
        Long tid=1286977770684948448l;
        return teacherService.findAllQuestion(tid);
    }

    @RequestMapping("/SetHomeWrok")
    public ResponseResult SetHomeWrok(@RequestParam("ids") String ids,@RequestParam("cid") Integer cid,
                                      @RequestParam("startTime") String startTime,
                                      @RequestParam("endTime")String endTime,@RequestParam("name")String name){
   return      teacherService.SetHomeWrokToStudent(ids,cid,startTime,endTime,name);

    }


/*
查看某一个课程下的所有作业
* */
    @RequestMapping("/show")
    public QueryResponseResult<HomeWrok_TDto> show(@RequestParam("cid") Integer cid){
     return    teacherService.show(cid);

    }
//**
// 查看某一个课程下 的某一个作业的所有学生的情况
// */

    @RequestMapping("/showDetail")
    public QueryResponseResult<StudentDto> showStudent(@RequestParam("hid") Long hid){
        return    teacherService.showStudent(hid);

    }
    @RequestMapping("/showContent")
    public QueryResponseResult<HomeWrokDetailDto_T> showContent(@RequestParam("sid") Long sid,@RequestParam("hid")Long hid){
      return   teacherService.showContent(sid,hid);
    }


    @RequestMapping("/test")
    public void  test(@RequestParam("ids") String ids){
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
        System.out.println(ids);
         List<IDTO> idtos = JSON.parseArray(ids, IDTO.class);
        final String[] split = ids.split(",");
        System.out.println(split.length);
    }

}
